<?php
/**
 * @filesource:					CommonCustomerAction.class.php
 * @desc:						客户管理公共类模块
 * 
 * @author:						shenyaqing
 * @copyright:					hou.yining@gmail.com
 * @date:						2011-04-21
 */
class CommonCustomerAction extends CommonAction{
	public function ___initialize(){
		$obj = D('admin_user');
		$result = $obj->where()->select();
		return $result;
	}
/**
	 * 重写父类insert方法
	 * */
	function insert() {
//		echo "<pre>";
//		var_dump($_POST);
	//	B('FilterString');
		$model = D ('general_customer');
		if (false === $model->create ()) {
			$this->error ( $model->getError () );
		}
		//保存当前数据对象
		$list=$model->add ();
		if ($list!==false) { //保存成功
			$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
			$this->success ('新增成功!');
		} else {
			//失败提示
			$this->error ('新增失败!');
		}
	}
	/***
	 * 重写父类delete方法
	 */
	public function delete() {
		//删除指定记录
	
		$model = M ('general_customer');
		if (! empty ( $model )) {
			$pk = $model->getPk ();
			$id = $_REQUEST [$pk];
			if (isset ( $id )) {
				$condition = array ($pk => array ('in', explode ( ',', $id ) ) );
				//放入回收站
				//$list=$model->where ( $condition )->setField ( 'status', - 1 );
				//彻底删除
				$list = $model->where($condition)->delete();
				if ($list!==false) {
					$this->success ('删除成功！' );
				} else {
					$this->error ('删除失败！');
				}
			} else {
				$this->error ( '非法操作' );
			}
		}
	}
	/**
	 * 重写父类view方法
	 * */
	public function view($name = ''){
		$model = M ( 'general_customer' );
		$id = $_REQUEST [$model->getPk ()];
		$vo = $model->getById ( $id );
		$this->assign ( 'vo', $vo );
		
		$this->display ();
	}
	/**
	 * 重写父类update方法
	 * */
	function update() {
		//B('FilterString');
		$model = D ( 'general_customer' );
		if (false === $model->create ()) {
			$this->error ( $model->getError () );
		}
		// 更新数据
		$list=$model->save ();
		if (false !== $list) {
			//成功提示
			$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
			$this->success ('编辑成功!');
		} else {
			//错误提示
			$this->error ('编辑失败!');
		}
	}
	//全选删除
	public function all_delete(){
    	$obj = D('general_customer');
		$zhi = $_GET['id']; 
		//var_dump($zhi);
		//echo strlen($zhi);die;
			//echo $zhi;  
	    $zhi=explode(',',$zhi);
	    //var_dump($zhi);die;
		//在循环删除就可以
		for($i=0;$i<count($zhi);$i++)
		{
		  $obj->query("delete from GMS_general_customer where id='$zhi[$i]'");
		  	 
		} 	
    }
}